package leetcode_301_400;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class LeeCode_387 {
    public static void main(String[] args) {
        System.out.println(firstUniqChar("loveleetcode"));
    }
    private static int firstUniqChar(String s) {
        char[] chars = s.toCharArray();
        Map<Character, Integer> map = new HashMap<>();
        for (char aChar : chars) {
            if (map.containsKey(aChar)) {
                map.put(aChar, map.get(aChar) + 1);
                continue;
            }
            map.put(aChar, 1);
        }
        for (int i = 0; i < chars.length; i++) {
            if (map.get(chars[i]) == 1)
                return i;
        }
        return -1;
    }
}
